from rest_framework import serializers

from .RemoteOJ import RemoteOJ
from .RobotAccount import RobotAccount


class RemoteOJSerializer(serializers.ModelSerializer):
    picture = serializers.SerializerMethodField()

    class Meta:
        model = RemoteOJ
        fields = (
            'id',
            'name',
            'picture',
            'baseurl',
            'description',
        )
        read_only_fields = ('id',)

    def get_picture(self, instance):
        return instance.picture.url


class ProblemAddRemoteOJSerializer(serializers.ModelSerializer):
    class Meta:
        model = RemoteOJ
        fields = (
            'id',
        )


class RobotsAccountSerializer(serializers.ModelSerializer):
    class Meta:
        model = RobotAccount
        fields = (
            'id',
            'username',
            'password',
            'remote_oj',
            'is_active',
        )
        read_only_fields = ('id',)
